package bsr.basara.autodata.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

/**
 * 雪花算法工具类
 *
 * @author basara
 */
public class SnowflakeUtil {

    private static final Snowflake SNOWFLAKE = IdUtil.createSnowflake(0, 0);

    public static synchronized long snowflakeId(long workerId, long datacenterId) {
        Snowflake snowflake = IdUtil.createSnowflake(workerId, datacenterId);
        return snowflake.nextId();
    }

    public static synchronized long getId() {
        return SNOWFLAKE.nextId();
    }

    public static synchronized String getIdStr() {
        return SNOWFLAKE.nextIdStr();
    }

}
